<script setup lang="ts">
const state = reactive({
  username: "",
  password: "",
});

const tokenCookie = useCookie("token");
const userCookie = useCookie("user");
const router = useRouter();
const msg = useState<string>("msg");
const route = useRoute();

const handleSubmit = async () => {
  const data = await $post<LoginResp>("/auth/login", state);
  console.log(data);
  tokenCookie.value = data?.auth.token;
  userCookie.value = JSON.stringify(data?.data);
  msg.value = "登录成功";
  router.replace(route.query.to || "/");
};
</script>

<template>
  <Form class="flex flex-col gap-y-2" @submit="handleSubmit">
    <FormInput label="账号" v-model="state.username" required />
    <FormInput label="密码" v-model="state.password" type="password" required />
  </Form>
</template>
